package com.wanmait.myhouse.webController;

import com.wanmait.myhouse.dao.HouseDAO;
import com.wanmait.myhouse.vo.House;
import com.wanmait.myhouse.vo.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("web")
public class WebrentingController {
    @GetMapping("renting")
    public String hotelSelection(Integer pon , Model model,House house){
        if("选择城市".equals(house.getCity()) || "".equals(house.getCity())){
            house.setCity(null);
        }
        if("选择类别".equals(house.getType()) || "".equals(house.getType())){
            house.setType(null);
        }
        if("卧室数量".equals(house.getRoom()) || "".equals(house.getRoom())){
            house.setRoom(null);
        }
        HouseDAO houseDAO = new HouseDAO();
        Pager pager = new Pager();
        if(pon == null){
            pon = 1;
        }
        pager.setPageNO(pon);//当前为第一页
        pager.setPageSize(4);//每页有4条数据
        int total =  houseDAO.getTotal(house,1);
        int pageCount = total/pager.getPageSize()+(total%pager.getPageSize()==0?0:1);
        pager.setPageCount(pageCount);
        model.addAttribute("pager",pager);
        List<House> houseList = houseDAO.FindPagerFall(pager,1,house);
        model.addAttribute("houseList",houseList);
        return "web/renting";
    }
}
